<template>
  <div>
    <el-checkbox-group v-model="check" @change="handleCheck">
      <el-checkbox
        v-for="(item, index) in list"
        :key="index"
        :label="item.value"
      >
        {{ item.name }}
      </el-checkbox>
    </el-checkbox-group>
  </div>
</template>

<script>
export default {
  name: 'CheckGroup',
  props: {
    list: {
      type: Array,
      default: () => {}
    },
    value: {
      type: String,
      default: ''
    }
  },
  model: {
    prop: 'value',
    event: 'check-value'
  },
  data() {
    return {
      check: []
    }
  },
  watch: {
    value() {
      this.setValue()
    }
  },
  created() {
    this.setValue()
  },
  methods: {
    setValue() {
      if (this.value) {
        this.check = this.value.split(',')
      }
    },
    handleCheck() {
      this.$emit('check-value', this.check.join(','))
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
